﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Mechanics.GameEventMechanics {
    import Mechanics.GameMechanicInterfaces.*;
    import Mechanics.*;
    import Classes.*;
    import Classes.util.*;
    import Mechanics.Transactions.*;

    public class DictionaryDataMechanicImplementation implements IDictionaryDataMechanic {

        private var m_owner:MechanicMapResource;
        private var m_config:MechanicConfigData;
        private var m_sendTransactions:Boolean;

        public function DictionaryDataMechanicImplementation(){
            this.m_sendTransactions = true;
        }
        public function add(_arg1:Object, _arg2:Object):Boolean{
            var _local3:Object = this.m_owner.getDataForMechanic(this.m_config.type);
            if (!_local3){
                _local3 = new Object();
            };
            _local3[_arg1] = _arg2;
            this.m_owner.setDataForMechanic(this.m_config.type, _local3);
            this.sendTransaction("add", _arg1, _arg2);
            return (true);
        }
        public function removeAt(_arg1:Object):Object{
            var _local2:Object = this.m_owner.getDataForMechanic(this.m_config.type);
            if (((!(_local2)) || (!(_local2[_arg1])))){
                return (null);
            };
            var _local3:Object = _local2[_arg1];
            delete _local2[_arg1];
            this.m_owner.setDataForMechanic(this.m_config.type, _local2);
            this.sendTransaction("removeAt", _arg1);
            return (_local3);
        }
        public function clear(_arg1:Boolean=true):Boolean{
            var _local2:Object = this.m_owner.getDataForMechanic(this.m_config.type);
            if (((!(_local2)) || ((GameUtil.countObjectLength(_local2) <= 0)))){
                return (false);
            };
            _local2 = new Object();
            this.m_owner.setDataForMechanic(this.m_config.type, _local2);
            if (_arg1){
                this.sendTransaction("clear");
            };
            return (true);
        }
        public function getKeys():Array{
            var _local3:Object;
            var _local1:Object = this.m_owner.getDataForMechanic(this.m_config.type);
            if (!_local1){
                return (null);
            };
            var _local2:Array = [];
            for (_local3 in _local1) {
                _local2.push(_local3);
            };
            return (_local2);
        }
        public function getValues():Array{
            var _local3:Object;
            var _local1:Object = this.m_owner.getDataForMechanic(this.m_config.type);
            if (!_local1){
                return (null);
            };
            var _local2:Array = [];
            for each (_local3 in _local1) {
                _local2.push(_local3);
            };
            return (_local2);
        }
        public function getValueAt(_arg1:Object):Object{
            var _local2:Object = this.m_owner.getDataForMechanic(this.m_config.type);
            if (((!(_local2)) || (!(_local2[_arg1])))){
                return (null);
            };
            return (_local2[_arg1]);
        }
        public function hasOverrideForGameAction(_arg1:String):Boolean{
            return ((this[_arg1] is Function));
        }
        public function executeOverrideForGameEvent(_arg1:String, _arg2:Array=null):MechanicActionResult{
            var _local3:MechanicActionResult = new MechanicActionResult(false, true);
            if ((this[_arg1] is Function)){
                _local3 = this[_arg1].apply(this, _arg2);
            };
            return (_local3);
        }
        public function initialize(_arg1:IMechanicUser, _arg2:MechanicConfigData):void{
            this.m_owner = (_arg1 as MechanicMapResource);
            this.m_config = _arg2;
        }
        public function isVisitEnabled():Boolean{
            return (false);
        }
        public function set sendTransactions(_arg1:Boolean):void{
            this.m_sendTransactions = _arg1;
        }
        protected function sendTransaction(_arg1:String, ... _args):void{
            if (this.m_sendTransactions){
                GameTransactionManager.addTransaction(new TMechanicAction(this.m_owner, this.m_config.type, MechanicManager.ALL, {
                    operation:_arg1,
                    args:_args
                }));
            };
        }

    }
}//package Mechanics.GameEventMechanics 
